<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import Room from './Room.vue'
import Order from './Order.vue'
import { Bell } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'

const router = useRouter()
const activeComponent = ref('room')

const switchComponent = (component) => {
  activeComponent.value = component
}

const logout = () => {
  ElMessageBox.confirm('确定要退出登录吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    localStorage.removeItem('token')
    localStorage.removeItem('user')
    router.replace({ path: '/login' })
    ElMessage.success('已退出客户端登录')
  }).catch(() => {
    return
  })
}
</script>

<template>
  <div class="home-container">
    <header class="header">
      <div class="logo-title-container">
        <div class="logo-container">
          <img src="../../assets/pic/Logo.png" alt="Logo" class="logo-image">
        </div>
        <div class="header-title">MeetKey 议启</div>
      </div>
      <nav class="nav-container">
        <div class="nav-menu">
          <div 
            class="nav-item" 
            :class="{ active: activeComponent === 'room' }"
            @click="switchComponent('room')"
          >
            <i class="nav-icon room-icon"></i>
            <span>会议室预约</span>
          </div>
          <div 
            class="nav-item" 
            :class="{ active: activeComponent === 'order' }"
            @click="switchComponent('order')"
          >
            <i class="nav-icon order-icon"></i>
            <span>订单管理</span>
          </div>
          <div class="nav-slider" :style="{ left: activeComponent === 'room' ? '3%' : '51%' }"></div>
        </div>
      </nav>
      <div class="logout-container">
        <button class="logout-btn" @click="logout">
          <i class="logout-icon"></i>
        </button>
      </div>
    </header>
    
    <main class="main-content">
      <component :is="activeComponent === 'room' ? Room : Order" />
    </main>
  </div>
</template>

<style scoped>
@font-face {
  font-family: 'HanYiYaKuHei';
  src: url('../../assets/fonts/汉仪雅酷黑-85.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

.home-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #a1cdf0;
}

.logo-title-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-container {
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 40px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.logo-image {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.header {
  padding: 0 9vh;
  display: grid;
  grid-template-columns: 200px 1fr 200px;
  align-items: center;
  height: 74px;
  position: relative;
  z-index: 10;
}

.nav-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.header-title {
  color: #2b2b2b;
  font-size: 20px;
  font-family: 'HanYiYaKuHei', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
}

.nav-menu {
  display: flex;
  position: relative;
  background-color: #2d6495;
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  width: 300px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.nav-item {
  flex: 1;
  color: #fff;
  padding: 6px 16px;
  cursor: pointer;
  position: relative;
  z-index: 2;
  transition: all 0.3s ease;
  text-align: center;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 500;
  border-radius: 12px;
}

.nav-item:hover {
  color: #d9e8f5;
}

.nav-item.active {
  color: #2d6495;
  font-weight: 600;
}

.nav-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: brightness(0) invert(1);
  transition: filter 0.3s ease;
}

.nav-item:hover .nav-icon {
  filter: brightness(0) invert(0.95);
}

.nav-item.active .nav-icon {
  filter: invert(33%) sepia(29%) saturate(1096%) hue-rotate(178deg) brightness(92%) contrast(87%);
}

.room-icon {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M19 19H5V5h14v14zm0-16H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 9h3v3h-3v-3zm0-5h3v3h-3V7zm-5 5h3v3H7v-3zm0-5h3v3H7V7z"/></svg>');
}

.order-icon {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M19 3h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm2 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z"/></svg>');
}

.nav-slider {
  position: absolute;
  background-color: rgba(255, 255, 255, 0.9);
  height: calc(100% - 16px);
  width: 46%;
  border-radius: 12px;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  top: 8px;
  z-index: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.logout-container {
  width: 200px;
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: flex-end;
}

.logout-btn {
  padding: 0%;
  background-color: rgba(255, 255, 255, 0.8);
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(45, 100, 149, 0.2);
}

.logout-btn:hover {
  background-color: rgba(255, 255, 255, 0.95);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(45, 100, 149, 0.25);
  border-color: rgba(45, 100, 149, 0.4);
}

.logout-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%232d6495"><path d="M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z"/></svg>');
  opacity: 0.8;
  transition: opacity 0.3s;
}

.logout-btn:hover .logout-icon {
  opacity: 1;
}

.main-content {
  flex: 1;
  background-color: transparent;
  overflow-y: auto;
}
</style>